1
|
|
|
'use strict' |
2
|
|
|
|
3
|
|
|
import './types/email' |
4
|
|
|
import Authenticable from './models/authenticable' |
5
|
|
|
import Registerable from './models/registerable' |
6
|
|
|
import Confirmable from './models/confirmable' |
7
|
|
|
import Lockable from './models/lockable' |
8
|
|
|
import Recoverable from './models/recoverable' |
9
|
|
|
import Trackable from './models/trackable' |
10
|
|
|
|
11
|
|
|
let options = {} |
12
|
|
|
|
13
|
|
|
export default function (schema, opt) { |
14
|
|
|
options = Object.assign({ |
15
|
|
|
confirmable: { |
16
|
|
|
tokenLifeSpan: 3 |
17
|
|
|
}, |
18
|
|
|
lockable: { |
19
|
|
|
tokenLifeSpan: 3, |
20
|
|
|
maximumAllowedFailedAttempts: 3 |
21
|
|
|
}, |
22
|
|
|
recoverable: { |
23
|
|
|
tokenLifeSpan: 3 |
24
|
|
|
}, |
25
|
|
|
registerable: { |
26
|
|
|
autoConfirm: false |
27
|
|
|
} |
28
|
|
|
}, opt) |
29
|
|
|
|
30
|
|
|
// implementation of notification send |
31
|
|
|
schema.methods.send = schema.methods.send || function (record, action, done) { |
32
|
|
|
done() |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
// format the string with the past values |
36
|
|
|
function stringFormat (key, values) { |
37
|
|
|
let message = options[key] |
38
|
|
|
if (values) { |
39
|
|
|
Object.keys(values).forEach(param => { |
40
|
|
|
message = message.replace(`{{${param}}}`, values[param]) |
41
|
|
|
}) |
42
|
|
|
} |
43
|
|
|
return message |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
// implementation of translator method |
47
|
|
|
function t (key, values) { |
48
|
|
|
return options.i18n |
49
|
|
|
? options.i18n.t(key, values) |
50
|
|
|
: stringFormat(key, values) |
51
|
|
|
} |
52
|
|
|
schema.methods.t = schema.methods.t || t |
53
|
|
|
schema.statics.t = schema.statics.t || t |
54
|
|
|
|
55
|
|
|
Authenticable(schema, options) |
56
|
|
|
Registerable(schema, options) |
57
|
|
|
Confirmable(schema, options) |
58
|
|
|
Lockable(schema, options) |
59
|
|
|
Recoverable(schema, options) |
60
|
|
|
Trackable(schema) |
61
|
|
|
} |
62
|
|
|
|